package com.bjtang.fileSync.util;

import java.lang.reflect.InvocationTargetException;
import java.nio.channels.SocketChannel;

import com.bjtang.fileSync.nio.FileService;
import com.bjtang.fileSync.nio.SocketDto;


public class GoTest {
	private FileService newInstance;

	public static void main(String[] args) {

//		Object[] args1 = new Object[2];
//		args1[0] = new String("2423432");
//		args1[1] = new SocketDto();
//		GoTest goTest = new GoTest();
//		goTest.MethodInvoke("sayBay", args1);
//		args1 = null;
//		goTest.MethodInvoke("sayHello", args1);
		GoTest goTest = new GoTest();
		goTest.MethodInvoke("sayHello", null,new SocketDto());
	}

	public void MethodInvoke(String s,SocketChannel socketChannel,SocketDto socketDto) {
		try {
			if (newInstance == null) {
				newInstance = FileService.class.getConstructor().newInstance();
			}
		
			FileService.class.getMethod(s, SocketChannel.class,SocketDto.class).invoke(newInstance, socketChannel,socketDto);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void MethodInvoke(String s, Object[] args) {
		try {
			if (newInstance == null) {
				newInstance = FileService.class.getConstructor().newInstance();
			}
			Class[] bClasses = null;
			if (args != null) {
				bClasses = new Class[args.length];
				for (int i = 0; i < args.length; i++) {
					bClasses[i] = args[i].getClass();
				}
			}
			FileService.class.getMethod(s, bClasses).invoke(newInstance, args);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
